package com.c2soft.nepalcmx.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.c2soft.nepalcmx.command.AccountDetailCommand;
import com.c2soft.nepalcmx.command.BrokerFormCommand;
import com.c2soft.nepalcmx.services.AccountDetailService;
import com.c2soft.nepalcmx.services.BrokerAccountDetailService;
import com.c2soft.nepalcmx.services.BrokerFormService;
import com.c2soft.nepalcmx.services.UserFormService;
import com.c2soft.nepalcmx.util.JsonUtil;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/mock")
public class MockServerController {
	@Autowired
		UserFormService userFormService;
	@Autowired
		AccountDetailService accountDetailService;
	@Autowired
	BrokerAccountDetailService brokeraccountDetailService;
	@Autowired
	BrokerFormService brokerFormService;
	
	
	
	@RequestMapping(value = "/bank", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<AccountDetailCommand> bank(HttpServletRequest req) {
		String userId=(String) req.getSession().getAttribute("UsrId");
		List<AccountDetailCommand> acc=accountDetailService.getAccounts(userId);
		return acc;
	}
	
	@RequestMapping(value = "/financial", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<AccountDetailCommand> financial(HttpServletRequest req) {
		String userId=(String) req.getSession().getAttribute("UsrId");
		List<AccountDetailCommand> acc=accountDetailService.getUserAccount(userId);
		return acc;
	}
	
	
	
	@RequestMapping(value = "/userbank", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<AccountDetailCommand> userbank(HttpServletRequest req) {
		String userId=(String) req.getSession().getAttribute("UsrId");
		List<AccountDetailCommand> acc=accountDetailService.getUserAccountsDetail(userId);
		return acc;
	}
	
	@RequestMapping(value = "/brokerbank", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<AccountDetailCommand> brokerbank(@RequestParam("brokeId") String brokeId) {
		List<AccountDetailCommand> acc=brokeraccountDetailService.getBrokerAccounts(brokeId);
		return acc;
	}
	
	@RequestMapping(value = "/bank1", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<AccountDetailCommand> bank1(@RequestParam("userId") String userId) {
		List<AccountDetailCommand> acc=accountDetailService.getAccounts(userId);
		return acc;
	}
	
	@RequestMapping(value = "/clientpage", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> client( HttpServletRequest req,HttpServletResponse resp) throws IOException {
	
		String userId=(String) req.getSession().getAttribute("UsrId");
		List<BrokerFormCommand> userList=userFormService.getUserList(userId);
		return userList;

		
	}
	
	@RequestMapping(value = "/clientpage1", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> client1( @RequestParam("userId") String userId) throws IOException {
		List<BrokerFormCommand> userList=userFormService.getUserList(userId);
		return userList;
	}
	
	
	
	@RequestMapping(value = "/brokerpage", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> brokerpage( @RequestParam("brokeId") String brokeId) throws IOException {
		List<BrokerFormCommand> brokerList=brokerFormService.getBrokerDetail(brokeId);
		return brokerList;	
	}
	
	@RequestMapping(value = "/brokerPass", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> brokerPass( HttpServletRequest req) throws IOException {
		String brokeId=(String) req.getSession().getAttribute("UsrId");
		List<BrokerFormCommand> brokerList=brokerFormService.getBrokerDetail(brokeId);
		return brokerList;
	}
	
	@RequestMapping(value = "/ExchangePass", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> ExchangePass( ) throws IOException {
		List<BrokerFormCommand> brokerList=userFormService.getExchangeDetail();
		return brokerList;
	}
		
	@RequestMapping(value = "/brok", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public String brok() {
		Map<String, String> brokDtlMap = new HashMap<String, String>();
		brokDtlMap.put("range", "01-JAN-2000-31-DEC-2050");
		brokDtlMap.put("sym", "null");
		brokDtlMap.put("btype", "NN");
		brokDtlMap.put("method", "Value");
		brokDtlMap.put("fixb", "0.0000");
		brokDtlMap.put("min", "0.0000");
		brokDtlMap.put("expb", "0.0000");
		brokDtlMap.put("sidef", "null");
		return JsonUtil.toJson(brokDtlMap); 
	}
	@RequestMapping(value = "/detail", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public List<BrokerFormCommand> detail(HttpServletRequest req) {
		/*Map<String, String> detailDtlMap = new HashMap<String, String>();
		detailDtlMap.put("cname", "Pankaj Kumar Sharma");
		detailDtlMap.put("pan", "CFQPS243E");
		detailDtlMap.put("add", "1234 D Lucknow");
		detailDtlMap.put("ctcl", "null");
		detailDtlMap.put("add1", "SGFERWSGERHSH");
		detailDtlMap.put("add2", "SGFERWSGERHSH");
		detailDtlMap.put("tradesc", "00000");
		detailDtlMap.put("add3", "SGFERWSGERHSH");
		detailDtlMap.put("email", "pankaj@18pixels.in");
		detailDtlMap.put("groupc", "null");
		detailDtlMap.put("phone", "9876543210");
		detailDtlMap.put("opend", "03-AUG-2013");
		detailDtlMap.put("brokid", "null");
		detailDtlMap.put("contype", "Digital");
		detailDtlMap.put("introducer", "0000000000");
		detailDtlMap.put("lst", "null");
		detailDtlMap.put("cst", "null");
		detailDtlMap.put("cashm", "CMP000");
		detailDtlMap.put("dailym", "MMP000");
		detailDtlMap.put("daily", "DMP000");
		detailDtlMap.put("dmp", "Y");
		detailDtlMap.put("sda", "C");
		detailDtlMap.put("tfa", "C");
		detailDtlMap.put("rma", "null");
		detailDtlMap.put("sttf", "C");
		//return JsonUtil.toJson(detailDtlMap); //JsonUtil will do object to json transformation for any
	                                    	//java object intended for UI operations
		*/
		String userId=(String) req.getSession().getAttribute("UsrId");
		List<BrokerFormCommand> userList=userFormService.getUserList(userId);
		return userList;
	}
	
	
	@RequestMapping(value = "/clientfundview", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json")
	@ResponseBody
	public String clientfundview() {
		Map<String, String> clientfundviewDtlMap = new HashMap<String, String>();
		clientfundviewDtlMap.put("id", "C0000");
		clientfundviewDtlMap.put("cname", "Pankaj Kumar Sharma");
		clientfundviewDtlMap.put("mobile", "9876543210");
		clientfundviewDtlMap.put("closeb", "100000");
		clientfundviewDtlMap.put("totm", "500000");
		clientfundviewDtlMap.put("depf", "20000");
		clientfundviewDtlMap.put("utim", "100000");
		clientfundviewDtlMap.put("withf", "10000");
		clientfundviewDtlMap.put("netp", "5000");
		clientfundviewDtlMap.put("balm", "400000");
		clientfundviewDtlMap.put("tot", "115000");
		
		return JsonUtil.toJson(clientfundviewDtlMap); 
	}
}
